function googleEngInit() {    	
	updateFormFields();
};


function updateFormFields() {
	updateGeneralConfigurationGUI();
};

function updateGoogleMapServerConfigurationGUI() {
/*   	emp.$('#enterpriseBaseURL').val(emp.configManager.mapEngine.enterpriseBaseURL);
   	emp.$('#enterpriseKey').val(emp.configManager.mapEngine.enterpriseKey);*/
   	emp.$('#defLat').val(emp.configManager.config.mapEngine.lat);
	emp.$('#defLon').val(emp.configManager.config.mapEngine.lon);
	emp.$('#defScale').val(emp.configManager.config.mapEngine.scale);
};

function updateGeneralConfigurationGUI() {
   	emp.$('#defLat').val(emp.configManager.config.generalConfig.lat);
	emp.$('#defLon').val(emp.configManager.config.generalConfig.lon);
	emp.$('#defScale').val(emp.configManager.config.generalConfig.scale);
};

function updateSelection(selection) {
		if (selection == "google") {
			emp.$('#geeEnterpriseUrlRow').fadeIn("slow");
			emp.$('#geeEnterpriseKeyRow').fadeIn("slow");
		} else {
			emp.$('#geeEnterpriseUrlRow').fadeOut("slow");
			emp.$('#geeEnterpriseKeyRow').fadeOut("slow");
		}
};

function updateMapConfig(url) {
		// get the form values
	var enterpriseBaseURL = emp.$('#enterpriseBaseURL').val();
	var enterpriseKey = emp.$('#enterpriseKey').val();
	var enableSynapse = 'false';
	var enableDebugging = 'false';
	var mapEngine = emp.$('#mapEngineSelection').val();
	var lat = emp.$('#defLat').val();
	var lon = emp.$('#defLon').val();
	var scale = emp.$('#defScale').val();
	
	emp.$.ajax({
		type: "POST",
		url: url,
		data: "enterpriseBaseURL=" + enterpriseBaseURL + "&enterpriseKey=" + enterpriseKey + "&enableSynapse=" + enableSynapse + "&enableDebugging=" + enableDebugging + "&mapEngine=" + mapEngine + "&lat=" + lat + "&lon=" + lon + "&scale=" + scale,
		success: function(response) {
			// remove error notification box 
			emp.$('#error-notification').hide('fast');   
			// we have the response
			if (response.status == "SUCCESS") {						
				updateEmpGeneralConfig();     
				updateFormFields();
				
				if (emp.$('#error-notification').is(":visible")) {
					emp.$('#error-notification').hide('slow');	
				}
			
			} else {
				errorInfo = "<ul>";					
				for (var i = 0; i < response.result.length; i++) {
					errorInfo += "<li>" + "Invalid Field " + "<span>" + response.result[i].field + "</span>: " + response.result[i].code + " : " + response.result[i].defaultMessage + "</li>";
				}
				errorInfo += "</ul>";						
				emp.$('#error-msg').html(errorInfo);
				emp.$('#success-notification').toggle('fast');
				emp.$('#error-notification').show('slow');					
			}					
		},
		error: function(e) {
			alert('Error: ' + e);				
		}								
	});		
};


function updateGeneralConfig(url) {
	var lat = emp.$('#defLat').val();
	var lon = emp.$('#defLon').val();
	var scale = emp.$('#defScale').val();
	
	emp.$.ajax({
		type: "POST",
		url: url,
		data: "&lat=" + lat + "&lon=" + lon + "&scale=" + scale,
		success: function(response) {
			// remove error notification box 
			emp.$('#error-notification').hide('fast');   
			// we have the response
			if (response.status == "Success") {						
				updateEmpGeneralConfig(response.result[0]);     
				updateFormFields();
				
				if (emp.$('#error-notification').is(":visible")) {
					emp.$('#error-notification').hide('slow');	
				}
			
			} else {
				errorInfo = "<ul>";					
				for (var i = 0; i < response.result.length; i++) {
					errorInfo += "<li>" + "Invalid Field " + "<span>" + response.result[i].field + "</span>: " + response.result[i].code + " : " + response.result[i].defaultMessage + "</li>";
				}
				errorInfo += "</ul>";						
				emp.$('#error-msg').html(errorInfo);
				emp.$('#success-notification').toggle('fast');
				emp.$('#error-notification').show('slow');					
			}					
		},
		error: function(e) {
			alert('Error: ' + e);				
		}								
	});		
};

function updateEmpGeneralConfig(data) {
	emp.configManager.config.generalConfig.lat   = data.lat;
	emp.configManager.config.generalConfig.lon   = data.lon;
	emp.configManager.config.generalConfig.scale = data.scale;
};